//
//  MineViewController.m
//  GiftThat
//
//  Created by ChuXiang on 16/1/6.
//  Copyright © 2016年 ChuXiang. All rights reserved.
//

#import "MineViewController.h"
#import "SFQCHCTableViewCell.h"
#import "SFShouCangViewController.h"
#import "QRCodeViewController.h"
#import "CXChangeColorViewController.h"
@interface MineViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UITableView *tableview;
@property (nonatomic,strong) UIImageView *Headerview;
@end

@implementation MineViewController

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewWillAppear:(BOOL)animated {
    self.navigationController.navigationBarHidden = YES;

}
- (void)viewDidLoad {
    [super viewDidLoad];

    [self GataTableView];
    
    self.Headerview = [[UIImageView alloc]initWithFrame:CGRectMake(0,  0, self.view.width, 200)];
    self.Headerview.image = [UIImage imageNamed:@"dise"];
    self.Headerview.contentMode = UIViewContentModeScaleAspectFill;
  
    [self.view addSubview:self.Headerview];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(self.view.width - 50, 30, 30, 30);
    [button setBackgroundImage:[UIImage imageNamed:@"saoma"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonDidPress:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(changeDay:) name:@"Color" object:nil];
    
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"Color"] isEqualToString:@"BlackColor"]) {
        self.tableview.backgroundColor = [UIColor colorWithRed:37 / 255.0 green:36 / 255.0 blue:40 / 255.0 alpha:1.0];
    }else{
        self.tableview.backgroundColor = [UIColor whiteColor];
    }
}

- (void) changeDay:(NSNotification *)message {
    if ([message.object isEqualToString:@"BlackColor"]) {
        self.tableview.backgroundColor = [UIColor colorWithRed:35 / 255.0 green:34 / 255.0 blue:38 / 255.0 alpha:1.0];
    }else {
        self.tableview.backgroundColor = [UIColor whiteColor];
    }
    [self.tableview reloadData];
}


-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat y =  scrollView.contentOffset.y;
    CGRect frame = self.Headerview.frame;
    frame.size.height = -y;
    self.Headerview.frame = frame;
}

-(void)GataTableView{
   
    self.tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, - 35, self.view.width, self.view.height) style:UITableViewStyleGrouped];
    self.tableview.contentInset = UIEdgeInsetsMake(200, 0, 0, 0);
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
//    self.tableview.scrollEnabled = NO;
    
    [self.tableview registerClass:[SFQCHCTableViewCell class] forCellReuseIdentifier:@"UIQCHCTableViewCellIdentifier"];
 
     [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UIShouCangTableViewCellIdentifier"];
    
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UIColorTableViewCellIdentifier"];
    [self.view addSubview:self.tableview];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
         SFQCHCTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UIQCHCTableViewCellIdentifier"];
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"Color"] isEqualToString:@"BlackColor"]) {
            cell.textLabel.textColor = [UIColor whiteColor];
            cell.backgroundColor = [UIColor colorWithRed:37 / 255.0 green:36 / 255.0 blue:40 / 255.0 alpha:1.0];
            
        }else{
            cell.textLabel.textColor = [UIColor blackColor];
            cell.backgroundColor = [UIColor whiteColor];
        }

        cell.imageView.image = [UIImage imageNamed:@"qingchu"];
        cell.textLabel.text = @"清除缓存";
        [cell.textLabel setFont:[UIFont fontWithName:@"FZLanTingHei-EL-GBK" size:15]];
            return cell;
    }else if (indexPath.row == 1) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UIColorTableViewCellIdentifier"];
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"Color"] isEqualToString:@"BlackColor"]) {
            cell.textLabel.textColor = [UIColor whiteColor];
            cell.backgroundColor = [UIColor colorWithRed:37 / 255.0 green:36 / 255.0 blue:40 / 255.0 alpha:1.0];
            
        }else{
            cell.textLabel.textColor = [UIColor blackColor];
            cell.backgroundColor = [UIColor whiteColor];
        }

        cell.imageView.image = [UIImage imageNamed:@"BackColor"];
        cell.textLabel.text = @"主题换肤";
        cell.detailTextLabel.text = @"官方红";
        [cell.textLabel setFont:[UIFont fontWithName:@"FZLanTingHei-EL-GBK" size:15]];
        return cell;
    }else if (indexPath.row == 2) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UIShouCangTableViewCellIdentifier"];
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"Color"] isEqualToString:@"BlackColor"]) {
            cell.textLabel.textColor = [UIColor whiteColor];
            cell.backgroundColor = [UIColor colorWithRed:37 / 255.0 green:36 / 255.0 blue:40 / 255.0 alpha:1.0];
            
        }else{
            cell.textLabel.textColor = [UIColor blackColor];
            cell.backgroundColor = [UIColor whiteColor];
        }

        cell.imageView.image = [UIImage imageNamed:@"Redaixin"];
        cell.textLabel.text = @"我的收藏";
        [cell.textLabel setFont:[UIFont fontWithName:@"FZLanTingHei-EL-GBK" size:15]];
        return cell;
    }
    
   
    return nil;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if (indexPath.row == 1) {
        CXChangeColorViewController *changeColor = [[CXChangeColorViewController alloc] init];
        [self.navigationController pushViewController:changeColor animated:YES];
    }
    if (indexPath.row == 2) {
        SFShouCangViewController *ShouCangViewController = [[SFShouCangViewController alloc]init];
        [self.navigationController pushViewController:ShouCangViewController animated:YES];
    }
}

-(void)buttonDidPress:(UIButton *)sender{
    QRCodeViewController *codeViewController = [[QRCodeViewController alloc]init];
    [self.navigationController pushViewController:codeViewController animated:YES];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
